package com.ee.chat.cps.admin.service.impl;

import com.ee.chat.common.bean.Result;
import com.ee.chat.common.dao.ChannelMapper;
import com.ee.chat.common.entity.Channel;
import com.ee.chat.cps.admin.service.IChannelOperationService;
import com.ee.chat.cps.admin.service.IChannelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Service
public class ChannelServiceImpl implements IChannelService {

    @Resource
    ChannelMapper channelMapper;
    @Resource
    IChannelOperationService operationService;

    /**
     * 编辑渠道商信息
     * @Author AppiJ
     * @Date 2020/3/28 16:50
     * @param
     * @return
     */
    @Override
    public Result toEdit(HttpServletRequest request, Integer id) throws Exception {
        Map<String, Object> data = new HashMap<>();

        Map<String, Object> channelUser = channelMapper.selectChannelVOById(id);
        if(channelUser == null){
            return Result.returnFailure("渠道商id错误");
        }
        data.put("channelUser", channelUser);

        operationService.addOperationLog(request, "查看渠道个人资料数据");

        return Result.returnSuccess(data);
    }

    /**
     * 保存渠道商信息
     * @Author AppiJ
     * @Date 2020/3/29 12:19
     * @param
     * @return
     */
    @Override
    public Result edit(HttpServletRequest request, Channel channel) throws Exception {
        channelMapper.updateById(channel);

        operationService.addOperationLog(request, "编辑个人资料");

        return Result.returnSuccess(null);
    }
}
